package com.leo.m1803.d11;

/**
 * Created by LEO on 2018/3/11.
 */
public class Offer11 {
    public static double pow(double a, int x){
        if (a==0 && x<1) { throw new RuntimeException("没意义啊"); }
        boolean isNeg = false;
        if (x<0){ isNeg = true; x = -x; }
        double res = pow01(a, x);
        if (isNeg) { res = 1.0/res; }
        return res;
    }
    private static double pow01(double a, int x){
        if (x == 0){ return 1; }
        if (x == 1){ return a; }
        double res = pow(a, x>>1);
        res *=res;
        if ((x&1) == 1){ res*=a; }
        return res;
    }

    public static void main(String[] args) {
        System.out.println(pow(1.1, 2));
    }
}
